package com.gyj.common;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * Created by Gao on 2018/5/23.
 */
@ApiModel
public class CommonResult<T> {

    @ApiModelProperty("是否成功")
    private boolean success = true;

    @ApiModelProperty("结果描述")
    private String message = "";

    @ApiModelProperty("连续请求串号，只有本地加元搜索的会用到此字段")

    private String sid;
    @ApiModelProperty("结果")

    private T result;

    public CommonResult(T result) {
        this.result = result;
    }

    public CommonResult(Exception e) {
        this.message = e.getMessage();
        this.success = false;
    }

    public CommonResult(Throwable e) {
        this.message = e.getMessage();
        this.success = false;
    }

    public String getSid() {
        return sid;
    }

    public void setSid(String sid) {
        this.sid = sid;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public String json() {
        return JSON.toJSONString(this);
    }

}